const {
  login
} = require('../controler/user')
const { SuccessModel, ErrorModel } = require('../model/resModel')
const handleUserRouter = (req, res) => {
  const path = req.url.split('?')[0]
  const method = req.method
  if (method === 'POST' && path === '/api/user/login') {
    const { username, password } = req.body
    const result = login(username, password)
    return result.then((res) => {
      if (res) {
        return new SuccessModel({})
      } else {
        return new ErrorModel({}, '登录失败')
      }
    }).catch(err => {
      return new ErrorModel({}, '登录失败')
    })
  }
}
module.exports = handleUserRouter